package sibu.cn.mydemo.androidmaterialdesign.androidui;

import android.animation.Animator;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import java.util.Random;

import sibu.cn.mydemo.R;
import sibu.cn.mydemo.androidmaterialdesign.androidui.action.BackAction;
import sibu.cn.mydemo.androidmaterialdesign.androidui.action.CloseAction;
import sibu.cn.mydemo.androidmaterialdesign.androidui.action.PlusAction;

public class AndroidUIActivity extends AppCompatActivity {

    boolean isFlag = true;
    RevealColorView revealColorView;
    ActionView actionView;
    int colors[] = new int[]{
            R.color.blue_transparent, R.color.cardview_shadow_start_color, R.color.colorPrimary, R.color.green_transparent, R.color.holo_green,
            R.color.red_transparent
    };

    Random random = new Random();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_android_ui);
        revealColorView = (RevealColorView) findViewById(R.id.reveal_color_view);
        actionView = (ActionView) findViewById(R.id.action_view);
        init();
    }

    public void init() {

        actionView.setAction(new BackAction(), true);
        actionView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isFlag) {
                    isFlag = false;
                    actionView.setAction(new CloseAction(), true);
                } else {
                    isFlag = true;
                    actionView.setAction(new PlusAction());
                }

                int i = random.nextInt(colors.length);

                revealColorView.reveal((int) v.getX(), (int) v.getY(),colors[i], new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }
                    @Override
                    public void onAnimationEnd(Animator animation) {

                    }
                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }
                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
            }
        });
    }


    public static void jumpAndroidUIActivity(Context context) {

        Intent intent = new Intent(context, AndroidUIActivity.class);
        context.startActivity(intent);
    }
}
